import request from '@/config/axios'
import { RuleFormType } from '@/views/Plant/BugRecord/types/BugRecord'

//新增
export const BugRecordPost = (data) => {
  return request.post({ url: '/1.1/classes/Diseases', data })
}
// 删除
export const BugRecordDel = (id: string) => {
  // 发起delete请求
  return request.delete({ url: `/1.1/classes/Diseases/${id}` })
}
// 编辑
export const BugRecordPut = (id: string, data: Omit<RuleFormType, 'objectId'>) => {
  // 发起put请求
  return request.put({ url: `/1.1/classes/Diseases/${id}`, data })
}

// 害虫信息列表
interface WhereType {
  Flora: { $regex: string; $options: 'i' }
}
//害虫列表
//page:number=1 当前第几页 不传时为第一页
//size:number=10 一页几条数据 不设置时默认10条
export const BugRecordGet = (page: number = 1, size: number = 15, condition?: { name: string }) => {
  const skip = (page - 1) * size //页数page *当前页条数size
  const where: WhereType = {} as WhereType
  if (condition && condition.name) {
    where.Flora = { $regex: condition.name, $options: 'i' }
  }
  const query = JSON.stringify(where)
  return request.get({
    url: `/1.1/classes/Diseases?where=${query}&limit=${size}&count=${1}&skip=${skip}`
    // params: {
    //   limit: size,
    //   count: 1, //开启对象计数(数据总条数)
    //   skip,//用来分页
    // }
  })
}
